Skip to content

Commit 86ee65a

Browse files
committed
fix broken test
1 parent 7cbdeca commit 86ee65a

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

kitsune/messages/views.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,36 @@ def preview_async(request):
185185

186186

187187
def _add_recipients(msg):
188+
"""Process and attach recipient information to a message object.
189+
190+
This helper function calculates recipient counts and assigns recipient-related
191+
attributes to the message object for both individual users and groups.
192+
193+
Args:
194+
msg: An OutboxMessage object to process.
195+
196+
Returns:
197+
The modified message object with the following attributes set:
198+
- recipients_count: Number of individual recipients
199+
- to_groups_count: Number of group recipients
200+
- recipient: The single recipient (if exactly one), else None
201+
- recipient.is_bot_user: Boolean indicating if recipient is SumoBot
202+
- to_groups: List of recipient groups with prefetched profiles
203+
204+
Note:
205+
The function assumes msg.to and msg.to_group are valid related fields
206+
on the message object.
207+
"""
188208
# Set the counts based on the lists
189209
msg.recipients_count = msg.to.all().count()
190210
msg.to_groups_count = msg.to_group.all().count()
191211

192212
# Assign the recipient based on the number of recipients
193213
msg.recipient = msg.to.all()[0] if msg.recipients_count == 1 else None
194214

195-
if msg.recipient.username == "SumoBot":
196-
msg.recipient.is_bot_user = True
197-
else:
198-
msg.recipient.is_bot_user = False
215+
# Set is_bot_user flag only if there's a recipient with a username
216+
if msg.recipient and hasattr(msg.recipient, "username"):
217+
msg.recipient.is_bot_user = msg.recipient.username == "SumoBot"
199218

200219
# Assign the group(s) based on the number of groups
201220
msg.to_groups = list(msg.to_group.prefetch_related("profile"))

0 commit comments

Comments
 (0)